package com.google.gwt.livinglife.client;

import java.util.Date;

import com.google.gwt.livinglife.client.data.BasicPostData;
import com.google.gwt.livinglife.client.data.UserIdData;
import com.google.gwt.livinglife.client.widgets.AuthoredTextBox;
import com.google.gwt.livinglife.client.widgets.BasicEntryForm;
import com.google.gwt.livinglife.client.widgets.SortedWidgetList;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.InlineHTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class PersonalizedPage {
	private LoginInfo login_info;
	private HorizontalPanel personalizedContents = new HorizontalPanel();;
	private VerticalPanel sideLinks = new VerticalPanel();
	private VerticalPanel mainPersonalizedPanel = new VerticalPanel();
	private DecoratorPanel todaysChallenges = new DecoratorPanel();
	private SortedWidgetList challenges_wrapper = new SortedWidgetList();
	private AuthoredTextBox[] userChallenges;
	private DeckPanel userPanels = new DeckPanel();
	private TabPanel groupsTabPanel = new TabPanel();
	private UserSettings user_settings;
	private VerticalPanel settingsPanel = new VerticalPanel();
	private VerticalPanel issue_challenge = new VerticalPanel();
	
	public PersonalizedPage() {
		user_settings = new UserSettings();
	}
	public void set_login_info(LoginInfo info) {
		user_settings.set_user_data(info.getUser_data());
	}
	public HorizontalPanel getPersonalizedContents() {
		return personalizedContents;
	}

	public void setPersonalizedContents(HorizontalPanel personalizedContents) {
		this.personalizedContents = personalizedContents;
	}

	public VerticalPanel getSideLinks() {
		return sideLinks;
	}

	public void setSideLinks(VerticalPanel sideLinks) {
		this.sideLinks = sideLinks;
	}

	public VerticalPanel getMainPersonalizedPanel() {
		return mainPersonalizedPanel;
	}

	public void setMainPersonalizedPanel(VerticalPanel mainPersonalizedPanel) {
		this.mainPersonalizedPanel = mainPersonalizedPanel;
	}

	public DecoratorPanel getTodaysChallenges() {
		return todaysChallenges;
	}

	public void setTodaysChallenges(DecoratorPanel todaysChallenges) {
		this.todaysChallenges = todaysChallenges;
	}

	public SortedWidgetList getChallenges_wrapper() {
		return challenges_wrapper;
	}

	public void setChallenges_wrapper(SortedWidgetList challengesWrapper) {
		challenges_wrapper = challengesWrapper;
	}

	public AuthoredTextBox[] getUserChallenges() {
		return userChallenges;
	}

	public void setUserChallenges(AuthoredTextBox[] userChallenges) {
		this.userChallenges = userChallenges;
	}

	public DeckPanel getUserPanels() {
		return userPanels;
	}

	public void setUserPanels(DeckPanel userPanels) {
		this.userPanels = userPanels;
	}

	public TabPanel getGroupsTabPanel() {
		return groupsTabPanel;
	}

	public void setGroupsTabPanel(TabPanel groupsTabPanel) {
		this.groupsTabPanel = groupsTabPanel;
	}

	public VerticalPanel getSettingsPanel() {
		return settingsPanel;
	}

	public void setSettingsPanel(VerticalPanel settingsPanel) {
		this.settingsPanel = settingsPanel;
	}

	
	public void draw() {
		userChallenges = new AuthoredTextBox[2];
		UserIdData userData = new UserIdData("Amit","foobar", "images/fase.png");
		BasicPostData postData = new BasicPostData("Take nightshot of something interesting outside your home and share it.", new Date(), userData, null);
		BasicPostData postData2 = new BasicPostData("Complete this rhyme: \"Mary had a little lamb ....\" with something creative", new Date(), userData, null);

		getUserChallenges()[0] = new  AuthoredTextBox(postData );
		getUserChallenges()[1] = new  AuthoredTextBox(postData2);
		
		challenges_wrapper.setWidgets(userChallenges);
		challenges_wrapper.getMenuBar().setVisible(false);
	}
	public void assemblePersonalizedPanel() {
		personalizedContents.setSpacing(5);
		personalizedContents.add(getSideLinks());
		Image blackBar = new Image("images/noimage.pmg");
		blackBar.setPixelSize(3, 700);
		personalizedContents.add(blackBar);
		personalizedContents.add(getMainPersonalizedPanel());
		mainPersonalizedPanel.setSpacing(5);
		mainPersonalizedPanel.setWidth("700px");
		mainPersonalizedPanel.add(todaysChallenges);
		todaysChallenges.setWidth("700px");
		mainPersonalizedPanel.add(issue_challenge);
		challenges_wrapper.setWidth("700px");
		mainPersonalizedPanel.add(new InlineHTML("<hr />"));
		mainPersonalizedPanel.add(userPanels);
		// Build the sideLinks
		final Hyperlink groupsLink = new Hyperlink("Groups", "Groups");
		sideLinks.add(groupsLink);
		final Hyperlink settingsLink = new Hyperlink("Settings", "Settings");
		sideLinks.add(settingsLink);
		final Hyperlink aliveMeterLink = new Hyperlink("AliveMeter", "AliveMeter");
		sideLinks.add(aliveMeterLink);
		// Build User Challenges
		todaysChallenges.add(getChallenges_wrapper());
		challenges_wrapper.setHeader("Your Challenges for the day");

		
		userPanels.add(groupsTabPanel);
		userPanels.add(user_settings.getMainPanel());
		groupsTabPanel.setSize("700px", "700px");
		groupsTabPanel.add(new Label("Here we will show the description of the group and some challenges"), "Root");
		groupsTabPanel.add(new Label("There should be links to go to group's homepage"), "UT Austin Friends");
		groupsTabPanel.add(new Label("Also some stats about the group would be nice"), "Amit's Family");
		
		groupsTabPanel.selectTab(0);

		userPanels.showWidget(0);
	}
}